package com.lagou.edu.code.controller;

import com.lagou.edu.api.IAuthCodeService;
import com.lagou.edu.common.bean.Response;
import com.lagou.edu.common.constant.ResponseCode;
import com.lagou.edu.common.utils.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * created by kirito at 2020/7/12
 */
@RestController
@RequestMapping("/code")
public class AuthCodeController {

    @Autowired
    private IAuthCodeService authCodeService;

    @GetMapping("/create/{email}")
    public Response createCode(@PathVariable(value = "email") String email) {
        Response response;
        try {
            authCodeService.createCode(email);
            response = ResponseUtil.response(ResponseCode.SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            response = ResponseUtil.response(ResponseCode.FAIL);
        }
        return response;
    }
}
